package com.hjp.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hjp.dao.IDepartmentDao;
import com.hjp.model.Department;
import com.hjp.service.IDepartmentService;

@Service
//@Transactional
public class DepartmentServiceImpl implements IDepartmentService {


	private IDepartmentDao  departmentDao;
	
	/**
	 * @param departmentDao the departmentDao to set
	 */
	@Resource
	public void setDepartmentDao(IDepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	@Override
	public List<Department> findTopList() {
		// TODO Auto-generated method stub
		return departmentDao.findTopList();
	}

	@Override
	public List<Department> findChildren(Long parentId) {
		// TODO Auto-generated method stub
		return departmentDao.findChildren(parentId);
	}
	
	@Override
	public void save(Department entity) {
		
		//System.out.println(entity.getName());		
		if (departmentDao.getByName(entity.getName()) == null) {
			
			System.out.println("此部门name不存在，可填");
			departmentDao.save(entity);
		} else {
			System.out.println("此部门name已存在，不可填");
		}
				
	}
	
	@Override
	public void delete(Long id) {
		departmentDao.delete(id);
	}

	@Override
	public void update(Department entity) {
		
		departmentDao.update(entity);
	}

	
	@Override
	public Department getById(Long id) {
		
		return departmentDao.getById(id);
	}
	
	@Override
	public List<Department> getByIds(Long[] ids) {
		
		return departmentDao.getByIds(ids);
	}
	
	@Override
	public List<Department> findAll() {
		
		return departmentDao.findAll();
	}
	
	/* (non-Javadoc)
	 * @see cn.itcast.oa.service.IDepartmentService#checkName(java.lang.String)
	 */
}
